var express = require('express')
var path = require('path')
var mongoose = require('mongoose')
var bodyParser = require('body-parser')
var port = process.env.PORT || 3000
var app = express()
mongoose.connect('mongodb://localhost/imooc')
app.set('views', './views/pages')
app.set('view engine', 'jade')
// 提交表单时，将数据格式化
app.use(bodyParser())
// 样式路径或脚本再 bower_components中查找
app.use(express.static(path.join(__dirname, 'bower_components')))
app.listen(port)

console.log('imooc started on' + port)

// index page
app.get('/',function (req, res) {
    res.render('index', {
        title: 'imooc 首页',
        movies: [
            {
                title: '机械战警',
                _id: 1,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 2,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 3,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 4,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            }
        ]
    })
})

// detail page
app.get('/movie/:id',function (req, res) {
    res.render('detail', {
        title: 'imooc  详情页',
        movie: {
            doctor: '何塞帕迪利亚',
            country: '美国',
            title: '机械战警',
            year: 2014,
            poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5',
            language: '英语',
            flash: 'http://player.youku.com/player.php/sid/XNjAnNjc0NTUy/v.swf',
            summary: '都发生了快递费激动死了咖啡机饿哦王 iu 肉鹅我脾气人'
        }
    })
})

// list page
app.get('/admin/list',function (req, res) {
    res.render('list', {
        title: 'imooc  列表页',
        movies: [
            {
                doctor: '何塞帕迪利亚',
                country: '美国',
                title: '机械战警',
                year: 2014,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5',
                language: '英语',
                flash: 'http://player.youku.com/player.php/sid/XNjAnNjc0NTUy/v.swf',
                summary: '都发生了快递费激动死了咖啡机饿哦王 iu 肉鹅我脾气人'
            }
        ]
    })
})

// admin page
app.get('/admin/movie',function (req, res) {
    res.render('admin', {
        title: 'imooc  后台录入页',
        movies: [
            {
                title: '机械战警',
                _id: 1,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 2,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 3,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            },
            {
                title: '机械战警',
                _id: 4,
                poster: 'http://r3.ykimg.com/05160000530EEB63675839160D0B79D5'
            }
        ]
    })
})